package org.jeecg.modules.extbpm.listener.task;

import org.activiti.engine.RuntimeService;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;
import org.jeecg.modules.extbpm.process.common.WorkFlowGlobals;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class SubProcessListener implements TaskListener{
	
	private static final long serialVersionUID = 1L;
	 
    @Autowired
    private RuntimeService runtimeService;

	@Override
	public void notify(DelegateTask delegateTask) {
		//获取主流程实例
		DelegateExecution execution =  delegateTask.getExecution();
		String mainProcessId = (String)execution.getVariable(WorkFlowGlobals.JG_SUB_MAIN_PROCESS_ID);
		String bizTitle = (String)runtimeService.getVariable(mainProcessId,WorkFlowGlobals.BPM_BIZ_TITLE);
		String businessKey = (String)runtimeService.getVariable(mainProcessId, WorkFlowGlobals.BPM_DATA_ID);
		execution.setVariable(WorkFlowGlobals.BPM_BIZ_TITLE, bizTitle);
		//子流程实例set业务号和主流程保持一致
        runtimeService.updateBusinessKey(delegateTask.getProcessInstanceId(), businessKey);
	}

}
